//
//  JMIPAssetCell.m
//  ImagePicker
//
//  Created by Jamin on 2018/10/17.
//  Copyright © 2018 jamin. All rights reserved.
//

#import "JMIPAssetCell.h"

#import "JMIPAsset.h"

#import "JMPhotosManager.h"
#import "JMImagePickerDefines.h"
#import "UIView+JMIP.h"
@interface JMIPAssetCell ()
@property (nonatomic, strong) UIImageView *imageView;       // The photo / 照片
@end

@implementation JMIPAssetCell

- (void)layoutSubviews {
    [super layoutSubviews];
    _imageView.jm_size = self.contentView.jm_size;
}

- (void)setAsset:(JMIPAsset *)asset {
    _asset = asset;
    
    [JMPhotosManager getPhotoWithAsset:asset.asset
                            photoWidth:JMIPAssetThumbnailLengh * 2
                            completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
        self.imageView.image = photo;
    }];
    
}

- (UIImageView *)imageView {
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.clipsToBounds = YES;
        [self.contentView addSubview:_imageView];
        
//        _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapImageView)];
//        [_imageView addGestureRecognizer:_tapGesture];
    }
    return _imageView;
}

@end
